package com.humble.vichatbackend.common;

import com.humble.vichatbackend.model.enums.ErrorCode;
import io.swagger.v3.oas.annotations.tags.Tag;

import lombok.Data;

@Data
@Tag(name="通用返回类")
public class BaseResponse<T> {
    private int code;

    private T data;

    private String message;

    private String description;

    public BaseResponse(int code, T data, String message, String description) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.description = description;
    }

    public BaseResponse(int code) {
        this(code, null, "", "");
    }

    public BaseResponse(int code, T data, String message) {
        this(code, data, message, "");
    }

    public BaseResponse(int code, T data) {
        this(code, data, "", "");
    }

    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(), null, errorCode.getMessage(), errorCode.getDescription());
    }

    public static <T> BaseResponse<T> success(T data){
        BaseResponse<T> response = new BaseResponse<T>(20000);
        response.data = data;
        return response;
    }

    public static <T> BaseResponse<T> success(T data, String message){
        BaseResponse<T> response = new BaseResponse<T>(20000);
        response.data = data;
        response.message = message;
        return response;
    }

    public static <T> BaseResponse<T> success(T data, String message,String description){
        BaseResponse<T> response = new BaseResponse<T>(20000);
        response.data = data;
        response.message = message;
        response.description = description;
        return response;
    }

    public static <T> BaseResponse<T> fail(ErrorCode errorCode){
        return new BaseResponse<T>(errorCode);
    }

    public static <T> BaseResponse<T> fail(T message){
        return new BaseResponse<T>(500,message);
    }

    public static <T> BaseResponse<T> fail(int errorCode){
        return new BaseResponse<T>(errorCode);
    }

    public static <T> BaseResponse<T> fail(int errorCode,String message){
        BaseResponse<T> response = new BaseResponse<>(errorCode);
        response.message = message;
        return response;
    }

    public static <T> BaseResponse<T> fail(int errorCode,String message,String description){
        BaseResponse<T> response = new BaseResponse<>(errorCode);
        response.message = message;
        response.description = description;
        return response;
    }
}
